<?php
session_start();
if(!isset($_SESSION['Username']))
{
  header("location:index.php");

}
else 
{
	if($_SESSION['Type']!=2)
  header("location:unauthorized.php");
	//echo isset($_SESSION['Username']);
	
}

include "dbconnect.php";
if(isset($_REQUEST['openingid']))
{
$openingID= $_REQUEST["openingid"];
$userName=$_SESSION["Username"];
$_SESSION['openingid']=$openingID;
}
else if($_SERVER["REQUEST_METHOD"] != "POST")
{
	header('location:professor.php');
	}
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$con=mysql_connect($dbHost,$dbUserAndName,$dbPass);
mysql_select_db($_DB_NAME,$con);
$userName=$_SESSION["Username"];
$openingID=$_SESSION["openingid"];
$result=mysql_query("Select * from openings where openingID='".$_SESSION["openingid"]."'");
$result=mysql_fetch_array($result);
if(empty($result["Comment"]))
{
	$Opening=mysql_query("Update openings set comment='".$_POST["comment"]."' where openingid='".$_SESSION["openingid"]."';");
}
else
{
	$Opening=mysql_query("Update openings set comment='".$result["Comment"]."&#10;".$_POST["comment"]."' where openingid='".$_SESSION["openingid"]."';");
}
if($Opening==false)
{
	die(mysql_error());}
 //unset($_SESSION['openingid']); 
//+"and year like '%"+$postyear+"%' order by year desc");
mysql_close($con);
}

$con=mysql_connect($dbHost,$dbUserAndName,$dbPass);
mysql_select_db($_DB_NAME,$con);
$userName=$_SESSION["Username"];	
$openingID=$_SESSION["openingid"];
$result=mysql_query("Select * from openings where openingID='".$_SESSION["openingid"]."'");
$result=mysql_fetch_array($result);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link href="CSS/Global.css" type="text/css" rel="stylesheet" />
<link href="CSS/Base.css" type="text/css" rel="stylesheet" />
<link href="CSS/Fixed.css" type="text/css" rel="stylesheet" />


<title>Comment</title>

<script src="media/js/jquery.js" type="text/javascript"></script>
<script src="media/js/jquery.datatables.js" type="text/javascript"></script>

  	<script type="text/javascript" src="scripts/jquery-2.0.3.min.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxexpander.js"></script>
   
	</script>

 <link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" />
 <link rel="stylesheet" href="jqwidgets/styles/jqx.summer.css" type="text/css" />
  
 <script type="text/javascript">
        $(document).ready(function () {
            // Create jqxExpander
            $("#openInfo").jqxExpander({});
			$('#userInfo').jqxExpander({});
        });
		
	</script>

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
    $('#datatables').dataTable(
	{	"bJQueryUI":true
		});
});
function validate()
{
	if(document.getElementById("comment").value=="" || document.getElementById("comment").value==null)
	{
		document.getElementById("lcomment").innerHTML="Comment is required";
		return false;
	}
	else
	{
		document.getElementById("lcomment").innerHTML="";
		return true;
	}
}
</script>

<style type="text/css">
@import "media/css/demo_table_jui.css";
@import "media/themes/smoothness/jquery-ui-1.8.4.custom.css";
</style>

</head>

<body style="min-width:1280px">

<div id="branding-bar" class="gateway">
<div class="bar">
<div class="wrapper">
<h1 class="campus"><a><img alt="Indiana University" height="73" src="Resources/img/trident-tab.gif.png" width="64"/>AIMS</a></h1>
</div>
</div>
</div>
<div class="grey">
</div>
<center>
			<div id="hnav"><!--system-region name="GLOBAL NAVIGATION"/-->
              <ul>
               <li style="width:200px;"><a href="professor.php">Comment</a></li>
                <li style="width:200px;" ><a href="profhire.php">Hiring</a></li>
              </ul>
      	</div>
        </center>
         <span style="width:100px;margin-left:300px;">
                <button class="hyperbutton" onclick="location.href = 'logout.php'" >logout</button>
         </span>
            <div class="footbody">
            <div id="openInfo">
                <div>
                Post Information
                </div>
                <div>
                <table class="registrationtable" cellpadding="5" cellspacing="5">
             <tbody>
             <tr>
                 <td>
                 <label >Course</label>
                 </td>
                 <td>
                 <label  class="crimson-text"><?php echo $result['courseid']; ?></label>
                 </td>
                 <td>
                 <label>Special Requirement</label>
                 </td>
                 <td>
                 <label  class="crimson-text"><?php echo $result['specialreq']?></label>
                 </td>
             </tr>
             <tr>
                 <td>
                 <label>Total</label>
                 </td>
                 <td
                 <label  class="crimson-text"><?php echo $result['Total']?></label>
                 </td>
                 <td>
                 <label >Filled</label>
                 </td>
                 <td>
                 <label  class="crimson-text"><?php echo $result["Filled"]?></label>
                 </td>
             </tr>
             <tr>
                 <td>
                 <label >Location</label>
                 </td>
                 <td>
                 <Textarea  disabled class="crimson-text"><?php echo $result["location"]?></textarea>
                 </td>
                 <td>
                 <label >Days</label>
                 </td>
                 <td>
                 <Textarea disabled="disabled"  class="crimson-text"><?php echo $result["Day"]?></textarea>
                 </td>
             </tr>
              <tr>
                 <td>
                 <label >Timings</label>
                 </td>
                 <td>
               	<Textarea disabled="disabled"  class="crimson-text"><?php echo $result["Timing"]?></textarea>
                 </td>
                <td>Comments</td>
             	<td>
                	<textarea disabled="disabled"=" class="crimson-text"><?php echo $result["Comment"]?></textarea>
                </td>
             </tr>
            </tbody>
             </table>
                </div>
              </div>
            <div id="userInfo" style="margin-top:20px">
                <div>
                Comment</div>
                <div>
                <form method="post" action="<?php echo basename(htmlspecialchars($_SERVER["PHP_SELF"]));?>" >
                <table class="registrationtable">
                <tbody>
                <tr>
           
                <td>
                <textarea id="comment" name="comment" rows="10" cols="50" class="crimson-border"> </textarea>
                <label id="lcomment" name="lcomment" for="lcomment"></label>
                </td>
                </tr>
                <tr>
                
                <td><input type="submit"  value="Comment" onclick="return validate()"/></td>
                </tr>
                </form>
                </tbody>
                </table>
                </div>
            </div>
           </div>
</body>
</html>